<?php

/**
 * 广告文件
 * ============================================================================
 * $Author: 王海龙 $
 * $Id: ad.php 2015-01-01 王海龙 $
*/

define('INIT_NO_SMARTY', true);
require(dirname(__FILE__) . '/includes/init.php');

/* 记录广告的点击量 */
if (!empty($_GET['id'])) {
    $id = intval($_GET['id']);
    $sql = "SELECT ad_link FROM `{$db->table('ad')}` ad WHERE ad.ad_id = '$id'";
    $ad_link = $db->getOne($sql);
    if (!empty($ad_link)) {
        /* 记录点击量 */
        $sql = "UPDATE `{$db->table('ad')}` SET click_count = click_count + 1 WHERE ad_id = '{$id}'";
        $db->query($sql);
        header("location: {$ad_link}");
        exit;
    } else {
        header("location: /index.php");
        exit;
    }
} else {
    header("location: /index.php");
    exit;
}
